package com.hh.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class AutoDAO {
	
	public JSONArray getSelect(String jdbcIp,String jdbcDatabase,String jdbcUser,String jdbcPassword,String jdbcSql){
		Connection con = null;
        PreparedStatement statement = null;
        ResultSet res = null;
        JSONArray array = new JSONArray();
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection("jdbc:sqlserver://"+jdbcIp+";DatabaseName="+jdbcDatabase,jdbcUser,jdbcPassword);
            statement = con.prepareStatement(jdbcSql);
            res = statement.executeQuery();
            int colNum = res.getMetaData().getColumnCount();
//            while(res.next()){
//            	res.get
//            	JSONObject o = new JSONObject();
//            	o.put("xm", res.getString("xm"));
//            	o.put("zxry", res.getString("zxry"));
//            	array.add(o);
//            }
            
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }finally{
            try {
                if(res != null) res.close();
                if(statement != null) statement.close();
                if(con != null) con.close();
            } catch (Exception e2) {
                // TODO: handle exception
                e2.printStackTrace();
            }
        }
        return array;
	}
}
